Ext.onReady(function(){ 

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'under';

var sm = new Ext.grid.CheckboxSelectionModel();
var cm=new Ext.grid.ColumnModel([ 
sm,
new Ext.grid.RowNumberer({header: "编号",width:40}),
{header:'客户号',dataIndex:'custNo',width:100},
{header:'客户名称',dataIndex:'custName',width:100},
{header:'违约事件类型',dataIndex:'eventType',width:100},
{header:'登记人',dataIndex:'inputUserId',width:100},
{header:'登记机构',dataIndex:'inputOrgId',width:100},
{header:'登记日期',dataIndex:'inputDate',width:100},
{header:'认定日期',dataIndex:'confirmDate',width:100,hidden:true},
{header:'违约事件流水号',dataIndex:'serialNo',hidden:true}
]); 

var ds=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'obligation/listCustDefaultEventToConfirm.do',
method:'POST'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'custNo', mapping:'cust.custNo'},
{name:'custName', mapping:'cust.custName'},
{name:'eventType', mapping:'custDE.eventType'},
{name:'inputUserId', mapping:'custDE.inputUserId'},
{name:'inputOrgId', mapping:'custDE.inputOrgId'},
{name:'inputDate', mapping:'custDE.inputDate'},
{name:'confirmDate', mapping:'custDE.confirmDate'},
{name:'serialNo', mapping:'custDE.serialNo'}
]) 
}); 
ds.load({params:{start:0,limit:20}}); 
var eventsTypeStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
		url:'showType.do?type=EventType',
		method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[{name:'name'}, {name:'code'}]) ,
	autoLoad:true
}); 
var classifyResultTypeStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
		url:'showType.do?type=ClassifyResult',
		method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[{name:'name'}, {name:'code'}]) ,
	autoLoad:true

}); 
var grid=new Ext.grid.GridPanel({ 
id:'contentList',
renderTo:"list", 
stripeRows:true,//斑马线效果
title:"违约事件认定-待认定列表", 
height:500, 
cm:cm,
store: ds, 
loadMask: { msg: "加载中..." }, 
viewConfig: {   
                            forceFit:true   
            },   
            bbar: new Ext.PagingToolbar({   
                pageSize: 20,   
                store: ds,   
                displayInfo: true,   
                displayMsg: '第{0} 到 {1} 条数据 共{2}条',   
                emptyMsg: "没有数据"   
            }),
 tbar: [
  {text:'退回登记人',handler:backToInput},
 '-',
  {text:'认定结果提交',handler:deConfirm},
   '-',
  {text:'详情',handler:checkDetail}
 ]              
});



//新增客户表单
addForm = new Ext.form.FormPanel({ 
id: 'addForm', 
width: 760, 
height: 420, 
//样式 
bodyStyle: 'margin:3px 3px 3px 3px', 
frame: true, 
xtype: 'filedset', 
labelWidth: 140, 
items: 
[ { xtype: 'fieldset', 
title: '客户违约事件信息', 
collapsible: true, 
autoHeight: true, 
autoWidth: true, 
items: 
[
 {
	 layout : "form",
     items : [{
     	xtype: 'textfield',
     	id: 'custId', 
     	name: 'custId', 
     	fieldLabel: '客户ID',
     	editable: false, 
     	readOnly: true,
     	hidden: true,
     	width: 200 
     }]
 },
 {layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
        layout : "form",
        items : [{
        	xtype: 'textfield',
        	id: 'custNo', 
        	name: 'custNo', 
        	fieldLabel: '客户号',
        	editable: false, 
        	readOnly: true,
        	width: 200 
        }]
    },{ 
        columnWidth : .5, // 该列有整行中所占百分比
        layout : "form",
        items : [{
        	
        }]
   }]
},{layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
        layout : "form",
        items : [{
        	xtype: 'textfield',
        	id: 'custName', 
        	name: 'custName', 
        	fieldLabel: '客户名称',
        	editable: false, 
        	readOnly: true,
        	width: 200 
        	 
        }]
    },{ 
        columnWidth : .5, // 该列有整行中所占百分比
        layout : "form",
        items : [{
        	xtype: 'textfield',
        	id: 'creditLevelBf', 
        	name: 'creditLevelBf', 
        	fieldLabel: '违约前评级',
        	allowBlank: true,
        	readOnly: true,
        	width: 200
        }]
   }]
},
{layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
        layout : "form",
        items : [{
        	xtype: 'combo', 
        	id : "eventType",
            store :eventsTypeStore,
            fieldLabel: '违约事件类型',
            valueField : 'code',
            displayField : 'name',
            emptyText : '',
        	readOnly: true,
            blankText:'',
            typeAhead : true,
            width: 200,
            mode:'remote',  
            hiddenName:'eventType',
            editable: false,
            triggerAction : 'all',
            selectOnFocus : true 
        }]
    },{ 
    	columnWidth : .5, // 该列有整行中所占百分比
        layout : "form",
        items : [{
        	xtype: 'datefield',
        	id: 'eventDate', 
        	name: 'eventDate', 
        	fieldLabel: '违约发生日期',  
        	allowBlank: true, 
        	readOnly: true,
        	editable:false, 
        	width:200 ,
        	format : 'Y-m-d'
        }]
    }]
},
{layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
        layout : "form",
        items : [{
	        xtype: 'textfield', 
			id:'capitalValue',
			name: 'capitalValue', 
			fieldLabel: ' 违约认定日本金余额(元)', 
			regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
	 	    regexText:'只能输入整数或小数！' , 
        	readOnly: true,
			width: 200
        }]
    },{
		columnWidth : .5, // 该列有整行中所占百分比
		layout : "form",
            items : [{
        	xtype: 'textfield', 
			id:'interestsValue',
			name: 'interestsValue', 
			fieldLabel: '未偿清利息总额(元)', 
			regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
 		    regexText:'请输入整数或小数' ,
        	readOnly: true, 
			width: 200
        }]
    }]
},
{layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
        layout : "form",
        items : [{
	        xtype: 'textfield', 
			id:'loanLimit',
			name: 'loanLimit', 
			fieldLabel: '违约认定日授信额度(元)', 
			regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
	 	    regexText:'只能输入整数或小数！' , 
        	readOnly: true, 
			width: 200
        }]
    },{
		columnWidth : .5, // 该列有整行中所占百分比
		layout : "form",
            items : [{
        	xtype: 'textfield', 
			id:'loanBalance',
			name: 'loanBalance', 
			fieldLabel: '违约认定日授信余额(元)', 
			regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
 		    regexText:'请输入整数或小数' , 
        	readOnly: true, 
			width: 200
        }]
    }]
},
{layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
        layout : "form",
        items : [{
        	xtype: 'combo', 
        	id : "classifyResult",
            store :classifyResultTypeStore,
            fieldLabel: '五级分类结果',
            valueField : 'code',
            displayField : 'name',
            emptyText : '',
            allowBlank : true,
        	readOnly: true,
            blankText:'',
            typeAhead : true,
            width: 200,
            mode:'remote',  
            hiddenName:'classifyResult',
            editable: false,
            triggerAction : 'all',
            selectOnFocus : true 
        }]
    },{ 
    	columnWidth : .5, // 该列有整行中所占百分比
        layout : "form",
        items : [{
        	xtype: 'datefield',
        	id: 'classifyDate', 
        	name: 'classifyDate', 
        	fieldLabel: '五级分类日期',  
        	allowBlank: true, 
        	readOnly: true,
        	editable:false, 
        	width:200 ,
        	format : 'Y-m-d'
        }]
    }]
},

{layout : "form",
	items : [{
		xtype: 'textarea',
		id: 'eventReason', 
		name: 'eventReason', 
		fieldLabel: '违约认定原因', 
		emptyText: '必填', 
		blankText: '原因描述不能为空', 
		maxLength:200,
		maxLengthText:'最多只允许输入200个汉字', 
		readOnly: true, 
		height:100,
		anchor: '97%' 
	}]
},
{layout : "form",
	items : [{
		xtype: 'textarea',
		id: 'eventDesc', 
		name: 'eventDesc', 
		fieldLabel: '违约事件描述', 
		emptyText: '必填', 
		blankText: '', 
    	readOnly: true, 
		maxLength:200,
		maxLengthText:'最多只允许输入200个汉字',
		height:100,
		anchor: '97%' 
	}]
},
{xtype:'hidden',
id:'serialNo',
name:'serialNo',
allowBlank: true
}

]}]
});

//新增窗口 
addWin = new Ext.Window({ 
id: 'addWin', 
title: '客户违约事件', 
width: 780, 
height: 500, 
//背景遮罩 
modal: true, 
//重置大小 
resizable: false, 
//当关闭按钮被点击时执行的动作 
closeAction: 'hide', 
plain: true, 
buttonAlign: 'right', 
items:addForm, 
buttons: 
[  
{ text: '关闭', handler: function() { Ext.getCmp('addWin').hide(); } }

] 
});

function deConfirm(){
	if (grid.getSelectionModel().getSelections()[0] == undefined) { 
		Ext.Msg.alert("提示", "请选中要操作的内容！"); 
	}
	else{
		var selectedId = grid.getSelectionModel().getSelections()[0].data.serialNo;
	
		Ext.MessageBox.confirm('提示', '确定提交此认定结果吗？', 
			confirm = function(btn){
			if (btn == 'yes') {
				Ext.Ajax.request({
					url:'obligation/deConfirm.do',
					params : { serialNo: selectedId},
					method:'POST',
			  		success:function(){
			  			window.parent.location.reload();
				  },failure:function(){
				    Ext.MessageBox.alert("请求异常！");
				  }
				});
				}}
			);
		 
	}
}

function backToInput(){
	if (grid.getSelectionModel().getSelections()[0] == undefined) { 
		Ext.Msg.alert("提示", "请选中要操作的内容！"); 
	}
	else{
		var selectedId = grid.getSelectionModel().getSelections()[0].data.serialNo;

		Ext.MessageBox.confirm('提示', '确定将结果退回登记人吗？', 
			confirm = function(btn){
			if (btn == 'yes') {
		Ext.Ajax.request({
		url:'obligation/backToInputUser.do',
		params : { serialNo: selectedId},
		method:'POST',
  		success:function(response){
		 	 grid.store.reload();
  },failure:function(){
    Ext.MessageBox.alert("请求异常！");
  }
});} });
}
}

function checkDetail(){
	if (grid.getSelectionModel().getSelections()[0] == undefined) { 
		Ext.Msg.alert("提示", "请选中要操作的内容！"); 
	}
	else{
		var selectedId = grid.getSelectionModel().getSelections()[0].data.serialNo;
		
		Ext.Ajax.request({
		url:'obligation/getCustDefaultEvent.do',
		params : { serialNo: selectedId},
		method:'POST',
  		success:function(response){
			var json = Ext.util.JSON.decode(response.responseText);
		 	Ext.getCmp('serialNo').setValue(json.custDE.serialNo);
		 	Ext.getCmp("custId").setValue(json.custDE.custId);
		 	Ext.getCmp("custNo").setValue(json.cust.custNo);
		 	Ext.getCmp("custName").setValue(json.cust.custName);
		 	Ext.getCmp("creditLevelBf").setValue(json.custDE.creditLevelBf);
		  	Ext.getCmp("eventType").setValue(json.custDE.eventType);
			Ext.getCmp("eventDesc").setValue(json.custDE.eventDesc);
		  	Ext.getCmp("eventDate").setValue(json.custDE.eventDate);
		  	Ext.getCmp("capitalValue").setValue(json.custDE.capitalValue);
		  	Ext.getCmp("interestsValue").setValue(json.custDE.interestsValue);
		  	Ext.getCmp("loanLimit").setValue(json.custDE.loanLimit);
		  	Ext.getCmp("loanBalance").setValue(json.custDE.loanBalance);
		  	Ext.getCmp("classifyResult").setValue(json.custDE.classifyResult);
		  	Ext.getCmp("classifyDate").setValue(json.custDE.classifyDate);
		  	Ext.getCmp("eventReason").setValue(json.custDE.eventReason);
			Ext.getCmp("addWin").show(); 
  },failure:function(){
    Ext.MessageBox.alert("请求异常！");
  }
});
	}
}

//grid.addListener('rowdblclick',checkDetail);
}); 